// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

typedef	struct WaitQ  WaitQ;
typedef	struct SudoG  SudoG;
typedef	struct Select Select;
typedef	struct Scase  Scase;
typedef struct Hchan  Hchan;

typedef struct	__go_type_descriptor	Type;
typedef struct	__go_channel_type	ChanType;

Hchan *__go_new_channel(ChanType *t, uintptr hint);
Hchan *__go_new_channel_big(ChanType *t, uint64 hint);
void __go_send_small(ChanType *t, Hchan* c, uint64 val);
void __go_send_big(ChanType *t, Hchan* c, byte* p);
uint64 __go_receive_small(ChanType *t, Hchan* c);
void __go_receive_big(ChanType *t, Hchan* c, byte* p);
void __go_builtin_close(Hchan *c);
int __go_chan_len(Hchan *c);
int __go_chan_cap(Hchan *c);

uintptr reflect_makechan(ChanType *, uint32) __asm__("reflect.makechan");
_Bool reflect_chansend(ChanType *, Hchan *, uintptr, _Bool) __asm__("reflect.chansend");
struct chanrecv_ret reflect_chanrecv(ChanType *, Hchan *, _Bool) __asm__("reflect.chanrecv");
void reflect_chanclose(uintptr) __asm__("reflect.chanclose");
int32 reflect_chanlen(uintptr) __asm__("reflect.chanlen");
int32 reflect_chancap(uintptr) __asm__("reflect.chancap");

Hchan* runtime_makechan_c(ChanType *t, int64 hint);
void runtime_closechan(Hchan *c);

void runtime_chansend(ChanType *t, Hchan *c, byte *ep, bool *pres);
void runtime_chanrecv(ChanType *t, Hchan* c, byte *ep, bool *selected, bool *received);
_Bool runtime_chanrecv2(ChanType *t, Hchan* c, byte* p) __asm__("runtime.chanrecv2");

_Bool runtime_selectnbsend(ChanType *t, Hchan *c, byte *p);
_Bool runtime_selectnbrecv(ChanType *t, byte *v, Hchan *c);
_Bool runtime_selectnbrecv2(ChanType *t, byte *v, _Bool *received, Hchan *c);

void* runtime_newselect(int) __asm__("runtime.newselect");
void runtime_selectsend(Select *, Hchan *, void *, int) __asm__("runtime.selectsend");
void runtime_selectrecv(Select *, Hchan *, void *, int) __asm__("runtime.selectrecv");
void runtime_selectrecv2(Select *, Hchan *, void *, bool *, int) __asm__("runtime.selectrecv2");
void runtime_selectdefault(Select *, int) __asm__("runtime.selectdefault");
int runtime_selectgo(Select *) __asm__("runtime.selectgo");
void runtime_block(void);
